package com.example.demo.service;

import com.example.demo.domain.User;
import com.example.demo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author Yimka
 *
 * @Date 2017/11/8 14:22
 */
@Service
@Transactional
@CacheConfig(cacheNames="user")
public class UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 保存一个用户
     * @param user
     */
    public void save(User user){
        userMapper.save(user);
    }

    @Cacheable
    public List<User> listAll() {
        return userMapper.listAll();
    }

    @Cacheable
    public User queryById(String id) {
        return userMapper.queryById(id);
    }
}
